//
// Created by 顾蛟 on 2020/7/2.
//

#include "MyGLRenderContext.h"

MyGLRenderContext* MyGLRenderContext::renderContext = nullptr;

MyGLRenderContext::MyGLRenderContext() {

}

MyGLRenderContext::~MyGLRenderContext() {

}

void MyGLRenderContext::onSurfaceCreated() {
    triangle.init();
}

void MyGLRenderContext::onSurfaceChanged(int width, int height) {
    //设置视点为(0, 0)，宽为width,高为height
    glViewport(0, 0, width, height);
}

void MyGLRenderContext::onDrawFrame() {
    triangle.draw();
}

MyGLRenderContext* MyGLRenderContext::getInstance() {
    if (renderContext == nullptr) {
        renderContext = new MyGLRenderContext();
    }
    return renderContext;
}

void MyGLRenderContext::destroyInstance() {
    if (renderContext) {
        delete renderContext;
        renderContext = nullptr;
    }
}

